package cn.xiangxiang.controller.goods;

import cn.xiangxiang.pojo.common.Result;
import cn.xiangxiang.pojo.goods.Template;
import cn.xiangxiang.service.goods.TemplateService;
import com.alibaba.dubbo.config.annotation.Reference;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/template")
public class TemplateController {

    @Reference
    private TemplateService templateService;

    @RequestMapping("/findall")
    public List<Template> findAll(){
        return templateService.list();
    }


    @PostMapping("/findconditionpage")
    public Page<Template> findConditionPage(Integer startpage, Integer pagesize, @RequestBody Template template){
        return templateService.findConditionPage(startpage,pagesize,template);
    }

    @GetMapping("/findbyid")
    public Template findById(Integer id){
        return templateService.getById(id);
    }

    @PostMapping("/save")
    public Result save(@RequestBody Template template){
        template.setParaNum(0);
        template.setSpecNum(0);
        templateService.save(template);
        return new Result();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Template template){
        templateService.updateById(template);
        return new Result();
    }

    @GetMapping("/delbyid")
    public Result delById(Integer id){
        templateService.delById(id);
        return new Result();
    }
}
